package com.wtwd.campus.receiver;

import com.wtwd.campus.annotation.MsgType;
import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.DeviceInfo;
import com.wtwd.campus.entity.MqGeneralValueResult;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.service.DeviceInfoService;
import com.wtwd.campus.utils.ReceiverUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@MsgType(value = Constants.RESET_M1_CARD)
public class ResetMCardReceiverHandler implements IReceiverHandler {

    @Override
    public void handlerMessage(MqMessage mqMessage) {
        // 指令无回复
//        MqGeneralValueResult mqGeneralValueResult = (MqGeneralValueResult) mqMessage.getObject();
//        String imei = mqGeneralValueResult.getImei();
//        String commandNumber = mqGeneralValueResult.getCommandNumber();
//        //处理指令回复的时间
//        String date = mqGeneralValueResult.getDeviceDate();
//        String time1 = mqGeneralValueResult.getDeviceTime();
//        Long time = getTime(date, time1);
//        String m1Card = mqGeneralValueResult.getValue();
//        DeviceInfo deviceInfo = deviceInfoService.getDeviceByImei(imei);
//        if (deviceInfo != null) {
//            //修改设备信息
//            deviceInfo.setLastUpTime((new Date()).getTime());//最后上传时间
//            deviceInfo.setM1Card(m1Card);
//            deviceInfoService.modifyDeviceInfo(deviceInfo);
//            //删除缓存中的指令
//            String delKey=Constants.RESET_M1_CARD.concat("-").concat(commandNumber);
//            receiverUtils.deleteCommandInRedis(imei, delKey);
//      /*      Integer flag=Constants.COMMAND_FAILED;
//            if(m1Card.equals(deviceInfo.getm1Card())){
//                //操作成功
//                flag=Constants.COMMAND_COMPLETE;
//            }*/
//            //完善指令下发记录
//            receiverUtils.completeCommandRecord(Constants.RESET_M1_CARD, imei, commandNumber, null, Constants.COMMAND_COMPLETE, time);
//    }
    }
}
